package com.dindang.propertyfee.mvp.ui.adapter.custom;

import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dindang.propertyfee.R;
import com.dindang.propertyfee.app.utils.TextViewUtils;
import com.dindang.propertyfee.mvp.model.entity.PropertyCharge;

import java.util.List;

/**物业费记录适配器*/
public class FeeOverdueViewAdapter extends RecyclerView.Adapter<FeeOverdueViewAdapter.ViewHolder> {
    List<PropertyCharge.Overdue> list;
    OnFeeOverdueListener listener;
    public FeeOverdueViewAdapter(List<PropertyCharge.Overdue> list, OnFeeOverdueListener listener) {
        this.list = list;
        this.listener = listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.propertyfee_item_fee_overdue, parent, false);
        FeeOverdueViewAdapter.ViewHolder viewHolder = new FeeOverdueViewAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        PropertyCharge.Overdue overdue = list.get(position);
        holder.tv_community_name.setText(overdue.bName);
        holder.tv_address.setText(overdue.addr);
        holder.tv_overdue.setText("逾期" + Math.abs(overdue.overdueDays) + "天");
        holder.tv_name_phone.setText(overdue.custName + "/" + overdue.c_telphone);
        holder.tv_total.setText(TextViewUtils.getOverdueAmount(overdue.amount));
        holder.tv_category.setText(overdue.c_fee_name);
        holder.constraintlayout.setOnClickListener(v -> listener.onClick(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        ConstraintLayout constraintlayout;
        TextView tv_community_name;
        TextView tv_address;
        TextView tv_overdue;
        TextView tv_name_phone;
        TextView tv_total;
        TextView tv_category;
        ViewHolder(View itemView) {
            super(itemView);
            constraintlayout = itemView.findViewById(R.id.propertyfee_constraintlayout);
            tv_community_name = itemView.findViewById(R.id.propertyfee_tv_community_name);
            tv_address = itemView.findViewById(R.id.propertyfee_tv_address);
            tv_overdue = itemView.findViewById(R.id.propertyfee_tv_overdue);
            tv_name_phone = itemView.findViewById(R.id.propertyfee_tv_name_phone);
            tv_total = itemView.findViewById(R.id.propertyfee_tv_total);
            tv_category = itemView.findViewById(R.id.propertyfee_tv_category);
        }
    }

    public interface OnFeeOverdueListener{
        void onClick(int position);
    }

}